from tkinter import messagebox
import tkinter as tk

from platforms.Jianshu import Jianshu
from Toutiao import Toutiao
from Zhihu import Zhihu

root = tk.Tk()
root.title("自媒体自动发布平台")
# root.resizable(0, 0)
# root.geometry("600x400")
tk.Label(root, text="标题：").grid(row=0, sticky="w", padx=5, pady=5)
tk.Label(root, text="主题：").grid(row=1, sticky="w", padx=5, pady=5)
tk.Label(root, text="内容：").grid(row=2, sticky="w", padx=5, pady=5)
tk.Label(root, text="图片：").grid(row=3, sticky="w", padx=5, pady=5)
title_entry = tk.Entry(root)
title_entry.grid(row=0, column=1, padx=5, pady=5, sticky='we')
theme_entry = tk.Entry(root)
theme_entry.grid(row=1, column=1, padx=5, pady=5, sticky='we')
desc_entry = tk.Text(root, height=30)
desc_entry.grid(row=2, column=1, padx=5, pady=5, sticky="we")
cover_entry = tk.Entry(root)
cover_entry.grid(row=3, column=1, padx=5, pady=5, sticky='we')


def click_zhihu():
    print("知乎按钮被点击")

    title = title_entry.get()
    theme = theme_entry.get()
    desc = desc_entry.get('1.0', tk.END)
    cover = cover_entry.get()
    if title is None or len(title) == 0:
        messagebox.showwarning("请输入标题！")
        return
    if theme is None or len(theme) == 0:
        messagebox.showwarning("请输入主题！")
        return
    if desc is None or len(desc) == 0:
        messagebox.showwarning("请输入描述内容！")
        return
    zhihu = Zhihu()
    ret = zhihu.start(cover, title, theme, desc)
    if ret is not None and ret != "":
        messagebox.showerror(ret)
    else:
        messagebox.showinfo("发布成功！")


def click_toutiao():
    print("头条按钮被点击")
    title = title_entry.get()
    theme = theme_entry.get()
    desc = desc_entry.get('1.0', tk.END)
    cover = cover_entry.get()
    if title is None or len(title) == 0:
        messagebox.showwarning("请输入标题！")
        return
    if theme is None or len(theme) == 0:
        messagebox.showwarning("请输入主题！")
        return
    if desc is None or len(desc) == 0:
        messagebox.showwarning("请输入描述内容！")
        return
    toutiao = Toutiao()
    ret = toutiao.start(cover, title, theme, desc)
    if ret is not None and ret != "":
        messagebox.showerror(ret)
    else:
        messagebox.showinfo("发布成功！")


def click_jianshu():
    print("简书按钮被点击")
    title = title_entry.get()
    desc = desc_entry.get('1.0', tk.END)
    cover = cover_entry.get()
    if title is None or len(title) == 0:
        messagebox.showwarning("请输入标题！")
        return
    if desc is None or len(desc) == 0:
        messagebox.showwarning("请输入描述内容！")
        return
    jianshu = Jianshu()
    ret = jianshu.start(cover, title,desc)
    if ret is not None and ret != "":
        messagebox.showerror(ret)
    else:
        messagebox.showinfo("发布成功！")


def click_qqhao():
    print("企鹅号按钮被点击")
    print(title_entry.get())
    print(desc_entry.get('1.0', tk.END))
    print(cover_entry.get())


button_frame = tk.Frame(root, padx=10, pady=10)
button_frame.grid(row=4, column=0, columnspan=2)
# 使用grid()函数来布局，并控制按钮的显示位置
tk.Button(button_frame, text="知乎", width=10, command=click_zhihu).grid(row=0, column=0, sticky="w", padx=10, pady=5)
tk.Button(button_frame, text="头条", width=10, command=click_toutiao).grid(row=0, column=1, sticky="e", padx=10, pady=5)
tk.Button(button_frame, text="简书", width=10, command=click_jianshu).grid(row=0, column=2, sticky="e", padx=10,
                                                                            pady=5)
tk.Button(button_frame, text="腾讯号", width=10, command=click_qqhao).grid(row=0, column=3, sticky="e", padx=10, pady=5)

# 开启事件主循环
root.mainloop()
